package com.learn.security.dto;

import com.fasterxml.jackson.annotation.JsonView;
import com.learn.security.validator.MyConstraint;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import java.util.Date;

public class User {

    // 简单视图
    public interface UserSimpleView {}
    // 全部的视图
    public interface UserDetailView extends UserSimpleView {}

    // @JsonView注解：申明所属视图
    @ApiModelProperty(value = "用户id")
    @JsonView(UserDetailView.class)
    private Integer id;

    @ApiModelProperty(value = "用户用户名")
    @JsonView(UserSimpleView.class)
    @Length(min = 2, max = 12,message = "用户名长度必须在2和12之间")
    @MyConstraint(message = "这是一个自定义校验测试")
    private String userName ;

    @ApiModelProperty(value = "用户真是姓名")
    @JsonView(UserSimpleView.class)
    @NotNull
    private String realName ;

    @JsonView(UserDetailView.class)
    @NotNull(message = "密码不能为空")
    private String password ;

    @JsonView(UserSimpleView.class)
    //@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8") 一般时间格式的信息不进行格式化
    @Past(message = "生日必须为过去的时间")
    private Date birthDay;

    public User() {
    }

    public User(Integer id, String userName, String realName, String password,Date birthDay) {
        this.id = id;
        this.userName = userName;
        this.realName = realName;
        this.password = password;
        this.birthDay = birthDay;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getBirthDay() {
        return birthDay;
    }

    public void setBirthDay(Date birthDay) {
        this.birthDay = birthDay;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", userName='" + userName + '\'' +
                ", realName='" + realName + '\'' +
                ", password='" + password + '\'' +
                ", birthDay=" + birthDay +
                '}';
    }
}
